package com.zhihaoliang.coroutine.buss.excep

import com.zhihaoliang.coroutine.buss.excep.func.*
import com.zhihaoliang.coroutine.common.list.ListActivity
import com.zhihaoliang.coroutine.common.list.ListItem

/**
 * @author 支豪亮
 * @date 2022/10/28 11:02
 * @des 异常处理
 */
class ExceptionActivity : ListActivity() {
    override val listItem: List<ListItem> = listOf(
        ListItem("Exception propagation", 0),
        ListItem("CoroutineExceptionHandler", 1),
        ListItem("Cancellation and exceptions Normal", 2),
        ListItem("Cancellation and exceptions Handle", 3),
        ListItem("Exceptions aggregation Normal", 4),
        ListItem("Exceptions aggregation Cancel", 5),
        ListItem("Supervision job", 6),
        ListItem("Supervision Scope", 7),
    )

    override fun onItemClick(item: ListItem) {
        when (item.index) {
            1 -> ExceptionHandler.handlerException(mainScope)
            2 -> ExceptionCanceler.cancelExceptionNormal(mainScope)
            3 -> ExceptionCanceler.cancelExceptionHander(mainScope)
            4 -> AggregationException.exceptionAggregationNormal(mainScope)
            5 -> AggregationException.exceptionAggregationCancel(mainScope)
            6 -> Supervision.supervisionJob(mainScope)
            7 -> Supervision.supervisionScope(mainScope)
            else -> ExceptionPropagation.propagationException(mainScope)
        }
    }

}